export function moreLineOpt(data) {
	console.log('moreLineOpt', data);
	return {
		color: ['#0091FF', '#37E4EC', '#8D54EE', '#41CE78', '#FFAE38', '#3CA272', '#FC8452', '#9A60B4', '#ea7ccc'],
		fontSize: '10',
		tooltip: {
			trigger: 'axis',
			axisPointer: {
				type: 'line',
				label: {
					backgroundColor: '#6a7985'
				}
			},
			position: function (pos, params, el, elRect, size) {
				var obj = { top: 'auto' };
				obj[['left', 'right'][+(pos[0] < size.viewSize[0] / 2)]] = 30;
				return obj;
			},
			textStyle: {
				textShadowBlur: 1
			},
			formatter: function (params) {
				var relVal = params[0].name;
				// console.log('moreLineOpt', params,data)
				for (var i = 0, l = params.length; i < l; i++) {
					relVal += '\n' + params[i].marker + params[i].seriesName + '：' + params[i].value + (params[i].componentIndex == 0 ? data.data[0].name == '已保养作业工单数' ? '单' : '小时' : '分钟');
				}
				return relVal;
			}
		},
		legend: {
			// padding: [0, 0, 0, 0],
			// bottom: '10',
			fontSize: '10',
			itemHeight: 10,
			itemWidth: 20,
			textStyle: {
				color: '#666',
				fontSize: '10'
			},
			top: 'bottom',
		},

		grid: {
			top: 30,
			bottom: 50
			// containLabel:true,
		},
		xAxis: [
			{
				lineStyle: {
					type: 'dashed'// 虚线
				},
				axisLine: {
					lineStyle: {
						color: '#999'
					},
				},
				axisTick: {
					inside: true,
					lineStyle: {
						color: '#999'
					}
				},

				type: 'category',
				boundaryGap: false,
				data: data.categories,
				axisLabel: {
					textStyle: {
						color: '#999',
					},
					formatter: function (date, index) {
						if (date.indexOf('月') != -1) {
							return date;
						} else {
							if (date.indexOf('~') != -1) {
								// 按周
								let arr = date.split('~');
								try {
									return (arr[0].slice(5) + '~' + arr[1].slice(5));
								} catch (e) {
									// TODO handle the exception
									return date;
								}
							} else {
								return (date.slice(5));
							}
						}
					},
				},
			}
		],
		yAxis: [
			{
				alignTicks: true,
				verticalAlign: 'top',
				name: data.data[0].name == '已保养作业工单数' ? '数量' : '小时',
				nameGap: 15,
				// minInterval: 1,
				nameLocation: 'end',
				nameTextStyle: {
					color: '#999',
					align: 'center'
				},
				type: 'value',
				axisLabel: {// y轴文字的配置
					textStyle: {
						color: '#999',// Y轴内容文字颜色
					},
				},
				splitLine: {
					lineStyle: {
						type: 'dashed',
						color: 'rgba(0,0,0,0.10)',
					},
				},
			},
			{

				alignTicks: true,
				verticalAlign: 'top',
				name: '分钟',
				nameGap: 15,
				nameLocation: 'end',

				position: 'right',
				nameTextStyle: {
					color: '#999',
					align: 'center'
				},
				type: 'value',
				axisLabel: {// y轴文字的配置
					textStyle: {
						color: '#999',// Y轴内容文字颜色
					},
				},
				splitLine: {
					lineStyle: {
						type: 'dashed',
						color: 'rgba(0,0,0,0.10)',
					},
				},
			}
		],
		series: data.data
	};
}

export function onelineOpt(data) {
	return {
		color: data.color || ['#0091FF', '#37E4EC', '#8D54EE', '#41CE78', '#FFAE38', '#3CA272', '#FC8452', '#9A60B4', '#ea7ccc'],
		fontSize: '10',
		tooltip: {
			trigger: 'axis',
			axisPointer: {
				type: 'line',
				label: {
					backgroundColor: '#6a7985'
				}
			},
			position: function (pos, params, el, elRect, size) {
				var obj = { top: 'auto' };
				obj[['left', 'right'][+(pos[0] < size.viewSize[0] / 2)]] = 30;
				return obj;
			},
			textStyle: {
				textShadowBlur: 1
			},
			formatter: function (params) {
				var relVal = params[0].name;
				// console.log('onelineOpt', params,data)
				for (var i = 0, l = params.length; i < l; i++) {
					relVal += '\n' + params[i].marker + params[i].seriesName + '：' + params[i].value + (data.unit ? data.unit : '');
				}
				return relVal;
			}
		},
		legend: {
			// padding: [0, 0, 0, 0],
			// bottom: '10',
			// height:50,
			// backgroundColor:'#ccc',
			fontSize: '10',
			itemHeight: 10,
			itemWidth: 20,
			textStyle: {
				color: '#666',
				fontSize: '10'
			},
			top: 'bottom',
		},

		grid: {
			top: 30,
			bottom: 60
			// containLabel:true,
		},
		xAxis: [
			{

				lineStyle: {
					type: 'dashed'// 虚线
				},
				axisLine: {
					lineStyle: {
						color: '#999'
					},
				},
				axisTick: {
					inside: true,
					lineStyle: {
						color: '#999'
					}
				},

				type: 'category',
				boundaryGap: false,
				data: data.categories,
				axisLabel: {
					textStyle: {
						color: '#999',
					},
					formatter: function (date, index) {
						if (date.indexOf('月') != -1) {
							return date;
						} else {
							if (date.indexOf('~') != -1) {
								// 按周
								let arr = date.split('~');
								try {
									return (arr[0].slice(5) + '~' + arr[1].slice(5));
								} catch (e) {
									// TODO handle the exception
									return date;
								}
							} else {
								return (date.slice(5));
							}
						}
					},
				},
			}
		],
		yAxis: [
			{
				alignTicks: true,
				verticalAlign: 'top',
				name: data.unit == '单'  ? '数量' : data.unit,

				nameGap: 15,
				nameLocation: 'end',
				nameTextStyle: {
					color: '#999',
					align: 'center'
				},
				type: 'value',
				axisLabel: {// y轴文字的配置
					textStyle: {
						color: '#999',// Y轴内容文字颜色
					},
				},
				splitLine: {
					lineStyle: {
						type: 'dashed',
						color: 'rgba(0,0,0,0.10)',
					},
				},
			}
		],
		series: data.data
	};
}

// 多y轴
export function setLineOptMore(data) {
	return {
		color: data.color || ['#0091FF', '#37E4EC', '#8D54EE', '#41CE78', '#FFAE38', '#3CA272', '#FC8452', '#9A60B4', '#ea7ccc'],

		type: 'line',
		padding: [15, 10, 0, 0],
		dataLabel: false,
		dataPointShape: true,
		enableScroll: false,
		// enableScroll: true,
		xAxis: {
			type: 'dash',
			gridColor: '#e5e5e5',
			gridType: 'dash',
			fontColor: '#999999',
			axisLineColor: '#666',
			// scrollShow: true,
			// itemCount: 4,
			labelCount: 5,
			fontSize: 11
		},
		yAxis: {
			gridType: 'dash',
			gridColor: '#e5e5e5',
			axisLineColor: '#fff',
			fontColor: '#999999',
			min: 0,
			fontSize: 11,
			splitNumber: 5,
			data: [{
				gridType: 'dash',
				gridColor: '#e5e5e5',
				axisLineColor: '#fff',
				fontColor: '#999999',
				min: 0,
				fontSize: 11,
				tofix: 1
			},
			{
				gridType: 'dash',
				gridColor: '#e5e5e5',
				axisLineColor: '#fff',
				fontColor: '#999999',
				position: 'right',
				min: 0,
				fontSize: 11,
				tofix: 0
			}
			]
		},
		legend: {
			itemGap: 15,
			fontColor: '#666666'
		},
		fontColor: '#999999',
		extra: {
			tooltip: {
				// fontColor:'#666',
				// labelFontColor:'#ccc',
				// borderOpacity:0.1,
				// borderRadius:3,
				// borderWidth:2,
				// bgColor:'#ffffff',
				// bgOpacity:1,
				showArrow: false,
				labelBgColor: '#ffffff',
				textStyle: {
					textShadowBlur: 1
				},
			},
			line: {
				type: 'curve',
				width: 2,
				gridType: 'dash'
			}
		}
	};
}
export function setLineOpt(data, types, color) {
	return {
		color: color ? color : ['#0091FF', '#37E4EC', '#8D54EE', '#41CE78', '#FFAE38', '#3CA272', '#FC8452', '#9A60B4', '#ea7ccc'],

		type: types ? types : 'area',
		padding: [15, 10, 0, 0],
		dataLabel: false,
		dataPointShape: true,
		enableScroll: false,
		// enableScroll: true,
		xAxis: {
			type: 'dash',
			gridColor: '#e5e5e5',
			gridType: 'dash',
			fontColor: '#999999',
			axisLineColor: '#666',
			labelCount: 5,
			fontSize: 11
		},
		yAxis: {
			gridType: 'dash',
			gridColor: '#e5e5e5',
			axisLineColor: '#fff',
			fontColor: '#999999',
			splitNumber: 5,
			min: 0,
			fontSize: 11,
			silent: true,
			tofix: data && data.tofix ? data.tofix : 0
		},
		legend: {
			itemGap: 15,
			fontColor: '#666666',
			lineHeight: 20,
			fontSize: 11
		},
		fontColor: '#999999',
		extra: {
			tooltip: {
				textStyle: {
					textShadowBlur: 1
				},
				showArrow: false,
				labelBgColor: '#ffffff'
			},
			line: {
				type: 'curve',
				width: 2,
				gridType: 'dash'
			},
			area: {
				type: 'curve',
				// type: 'straight',
				opacity: 0.2,
				addLine: true,
				width: 2,
				gradient: false
			}
		}
	};
}
export function setBarOpt(datas) {
	return {
		color: ['#6FA9FF', '#0091ff', '#B59CFE', '#FBCB92', '#FFAE38', '#3CA272', '#FC8452', '#9A60B4', '#ea7ccc'],
		type: 'bar',
		padding: [15, 30, 0, 5],
		dataLabel: false,
		dataPointShape: true,
		enableScroll: false,
		showTitle: true,
		// enableScroll: true,
		xAxis: {
			// gridColor: '#e5e5e5',
			gridType: 'dash',
			// fontColor: '#999999',
			// axisLineColor: '#666',
			// labelCount: 5,
			// fontSize: 11,
			// disableGrid: false,
			// boundaryGap: "justify",
			hideTofix: true,
			min: 0,
			axisLine: true,
			axisLineColor: '#333',
			max: datas.max || 0
		},
		yAxis: {
			disabled: false,
			disableGrid: false,
			splitNumber: 5,
			gridType: 'dash',
			dashLength: 8,
			gridColor: '#CCCCCC',
			padding: 10,
			min: 0,

			showTitle: false,

			// data: []
			data: [{
				// disabled:true,
				type: 'categories',
				axisLineColor: '#333',
				axisLine: true
			}]
		},
		legend: {
			show: false,
			// itemGap:10,
			margin: 5,
			padding: 5
		},
		fontColor: '#999999',

		extra: {
			tooltip: {
				textStyle: {
					textShadowBlur: 1
				},
				showArrow: false,
				labelBgColor: '#ffffff'
			},

			bar: {
				type: 'stack',
				width: 14,
				meterBorde: 1,
				meterFillColor: '#999',
				activeBgColor: '#fff',
				activeBgOpacity: 0.0,
				categoryGap: 2,
				linearType: 'custom'
				// barBorderCircle: true,
			}
		}
	};
}
export function setRingOpt(opts = {}, name) {
	return {
		color: opts && opts.color ? opts.color : ['#F47D99', '#6FA9FF', '#B59CFE', '#87E7B4', '#DDF474', '#3CA272',
			'#FC8452', '#9A60B4', '#ea7ccc'
		],

		tooltip: {
			trigger: 'item',
			show: false
		},
		legend: {
			show: true,
			orient: 'vertical',
			top: 'center',
			right: '20',
			icon: 'circle'
		},

		series: [
			{
				name: name,
				type: 'pie',
				// radius: ['50%', '90%'],
				radius: opts.type == 'pie' ? '90%' : ['40%', '70%'],
				center: ['90', '50%'],
				label: {
					show: false,
					position: 'center',
					formatter: function (lable) {
						let text = lable.data.name;
						if (text && text.indexOf('(')) {
							text = text.split('(')[0];
						}
						return [
							`{d|${lable.data.value}}{d|%}`,
							`{b|${text && text.length > 6 ? text.slice(0, 5) + '...' : text}}`
						].join('\n');
					},

					rich: {
						d: {
							fontSize: '18',
							fontWeight: 'bold',
							lineHeight: '22'
						},
						b: {
							fontSize: '12',
							color: '#999999'
						},

					}
				},
				itemStyle: {
					borderColor: '#fff',
					borderWidth: 2
				},
				emphasis: {
					label: {
						show: opts.type == 'pie' ? false : true,
						// position: 'center',
						color: '#333',
						// fontSize: '30',

					},
				},
				labelLine: {
					show: false
				},
				data: opts.data

			}
		]
	};
}

export function setPieOpt(opts = {}, name) {
	return {
		color: opts && opts.color ? opts.color : ['#F47D99', '#6FA9FF', '#B59CFE', '#87E7B4', '#DDF474', '#3CA272',
			'#FC8452', '#9A60B4', '#ea7ccc'
		],

		tooltip: {
			trigger: 'item',
			show: true,
			confine: true,
			textStyle: {
				textShadowBlur: 1
			},
			// position: ['40%', '30%'],
			formatter: function (lable) {
				console.log('formatter', lable);

				return [
					`{d|${lable.data.name}}`,
					`{b|数量:${lable.data.value}}`,
					`{b|占比:${lable.data.ratio}}{b|%}`
				].join('\n');
			},

		},
		legend: {
			show: true,
			orient: 'vertical',
			top: 'center',
			right: '20',
			icon: 'circle'
		},
		title: {
			text: opts.subtext || '',
			subtext: opts.title || '合同总数',
			left: '100',
			top: '43%',
			padding: [0, 0],
			// backgroundColor:'#ccc',
			textAlign: 'center',
			width: '400',
			lineHeight: 20,
			itemGap: 0,
			textStyle: {
				color: '#333',
				fontSize: 18,
				align: 'center',
			},
			subtextStyle: {
				color: '#999999',
				fontSize: 12,
				align: 'center',
				lineHeight: 20,
			},
		},

		series: [
			{
				name: name,
				type: 'pie',
				// radius: ['50%', '90%'],
				radius: opts.type == 'pie' ? '90%' : ['40%', '70%'],
				center: ['100', '50%'],
				label: {
					show: false,

				},
				itemStyle: {
					borderColor: '#fff',
					borderWidth: 2
				},
				emphasis: {
					show: false,
					label: {
						show: false,
						color: '#333',
						// fontSize: '30',

					},
				},
				labelLine: {
					show: false
				},
				data: opts.data

			}
		]
	};
}

// 合同维保统计圆饼图
export function contractPieOpt(opts = {}, typeName) {
	return {
		color:
			opts && opts.color
				? opts.color
				: [
					'#F47D99',
					'#6FA9FF',
					'#B59CFE',
					'#87E7B4',
					'#DDF474',
					'#3CA272',
					'#FC8452',
					'#9A60B4',
					'#ea7ccc',
				],

		tooltip: {
			trigger: 'item',
			confine: true,
			textStyle: {
				textShadowBlur: 1
			},
			formatter: function (params) {
				return params.data.pName + '\n' + params.marker + ' ' + params.data.name + '  ' + params.data.value + '(' + params.data.pro + '%)';
			},
			show: opts.tooltips || false,
			position: 'right'
		},
		legend: {
			show: true,
			orient: 'vertical',
			//   align:"left",
			top: 'center',
			left: opts.contract ? '47%' : '50%',
			// right: opts.contract?"27%":"10%",
			icon: 'circle',
			// width:220,

			formatter: function (name) {
				let arr = opts.data || [];
				let str = '';
				arr.map((item, i) => {
					if (name == item.name && (typeName === 'contractMain' || typeName === 'contractCast')) {// 维保电梯
						str = `{name|${item.name && item.name.length > 6 ? item.name.slice(0, 6) + '...' : item.name}}{val|${'  ' + item.value + '台'}}{pro|${item.pro + '%'}}`;
					}
					if (name == item.name && typeName === 'contractUnder') {// 在保电梯
						str = `{name${i}|${item.name}\n${item.nameType}}{val${i}|${'  ' + item.value + '台'}}{pro${i}|${item.pro + '%'}}`;
					}
				});

				return str;
			},
			textStyle: {
				fontSize: 13,
				//   color: 'inherit',
				color: '#666',
				align: 'right',
				rich: {
					name: {
						// width:opts.richWidth || 45,
					},
					name0: {
						// width:opts.richWidth || 45,
						color: '#E02020'
					},
					name1: {
						// width:opts.richWidth || 45,
						color: '#F79700'
					},
					name2: {
						// width:opts.richWidth || 45,
					},
					val: {
						width: 36,
						align: 'right',
					},
					val0: {
						color: '#E02020',
						width: 45,
						align: 'right',
					},
					val1: {
						color: '#F79700',
						width: 45,
						align: 'right',
					},
					val2: {
						width: 45,
						align: 'right',
					},
					pro: {
						width: 36,
						align: 'right',
					},
					pro0: {
						color: '#E02020',
						width: 40,
						align: 'right',
					},
					pro1: {
						color: '#F79700',
						width: 40,
						align: 'right',
					},
					pro2: {
						width: 40,
						align: 'right',
					}

				},
			},

		},

		series: [
			{
				//   name: name,
				type: 'pie',
				// radius: ['50%', '90%'],
				radius: opts.type == 'pie' ? '90%' : ['40%', '70%'],
				center: opts.contract ? ['80', '50%'] : ['90', '50%'],
				label: {
					show: false,
					position: 'center',
					formatter: function (lable) {
						//  console.log("lable",lable)
						let text = lable.data.name;
						if (typeName === 'contractUnder') {// 在保电梯
							text = lable.data.name + lable.data.nameType;
						}
						return [
							`{d|${lable.data.pro || lable.percent}}{d|%}`,
							`{b|${text && text.length > 6 ? text.slice(0, 6) + '...' : text
							}}`,
						].join('\n');
					},
					rich: {
						d: {
							fontSize: '18',
							fontWeight: 'bold',
							lineHeight: '22',
							color: '#333'
						},
						b: {
							fontSize: '12',
							color: '#999999',
						},
					},
				},
				itemStyle: {
					borderColor: '#fff',
					borderWidth: 2,
				},
				emphasis: {
					label: {
						show: opts.type == 'pie' ? false : true,
						//   show: false,
						// position: 'center',
						color: '#333',
						// fontSize: '30',
					},
					// scale:false,
					// disabled:true
				},
				labelLine: {
					show: false,
				},
				data: opts.data,
			},
		],
	};
}
